<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<link rel="stylesheet" href="style/weui/weui.min.css"/>
<script type="text/javascript" src="script/jquery-2.1.4.js"></script>
<script type="text/javascript" src="script/commonjs.js?p"></script>
<title><spring:message code="appheader"/></title>
<style type="text/css">
body{
    background-color: #efeff4;
}
.weui_label{
    white-space: nowrap;
    width: 5em;
}
.weui_select{
    padding-left: 0;
}
</style>
</head>
<body>
<form action="<c:url value="/account/authaccount.od"/>" method="post">
    <div class="weui_cells_title"><spring:message code="accountAuthTile" /></div>
    <div class="weui_cells weui_cells_form">
        <div class="weui_cell">
            <div class="weui_cell_hd">
                <label class="weui_label"><spring:message code="accountName"/></label>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" name="weChatId" type="number" pattern="[0-9]*" placeholder="<spring:message code="accountName"/>">
            </div>
        </div>
    <!--     <div class="weui_cell weui_cell_select">
            <div class="weui_cell_hd">
                <div class="weui_label" style="padding-left: 15px;">操作类型</div>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <select class="weui_select">
                    <option selected="" value="1">挂失</option>
                    <option value="2">解挂</option>
                </select>
            </div>
        </div> -->
        <div class="weui_cell">
            <div class="weui_cell_hd">
                <div class="weui_label"><spring:message code="password"/></div>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <input type="number" name="cellPhone" class="weui_input" />
            </div>
        </div>
    </div>

    <div class="weui_btn_area">
        <input type="submit" class="weui_btn weui_btn_primary" value="<spring:message code="submit"/>">
    </div>
</form>

    <div id="errorList" style="width:100%; height: 300px; overflow: auto;"></div>
<script>
var stopFlag;
function toOrder(id,name,price){
    //var ids = $("#orderList tr td:nth-child(1)");
    stopFlag = false;
    $("#orderList tr").each(function(){
        //console.log($(this).children("td:first").text())
        if (id == $(this).children("td:first").text()) {
            $(this).children("td:last").text(parseInt($(this).children("td:last").text()) + 1);
            stopFlag = true;
            return false;
        }
    });
    if (!stopFlag)
        $("#orderList").append("<tr style=\"vertical-align: top; height: 30px;\" ondblclick=\"removeOrder(this);\" onmouseover=\"javascript: this.style.backgroundColor = 'red';\" onmouseout=\"javascript: this.style.backgroundColor = 'white';\"><td style=\"display: none;\">"+ id +"</td><td style=\"width: 170px; font-size: 16px; height: 30px; vertical-align: top;\">"+ name +"</td><td style=\"display: none;\">"+ price +"</td><td style=\"width: 40px; font-size: 16px; height: 30px; vertical-align: top;\">1</td></tr>");
    
    $("#totalNo").text(parseInt($("#totalNo").text())+1).css("background-color","rgb(224,60,31)");
    $("#totalPrice").text(parseFloat($("#totalPrice").text()) + parseFloat(price)).css("background-color","rgb(224,60,31)");
}

function removeOrder(obj) {
    $(obj).remove();
    $("#totalPrice").text(parseFloat($("#totalPrice").text() - parseFloat($(obj).children("td:nth-child(3)").text())));
    $("#totalNo").text(parseInt($("#totalNo").text())-1);
}

function generOrder(formId){
    console.log(JSON.stringify(convertForm2Json("#"+formId)));
//    console.log($("#"+formId+"action").val() + convertForm2Json(formId));
    var ajaxUrl = $("#"+formId+"action").val();
    $.ajax({url: ajaxUrl,
           data: JSON.stringify(convertForm2Json("#"+formId)),
           dataType: "json",
           contentType: "application/json",
           type: "POST",
           success: function(HttpRequest, textStatus, errorThrown, data){
               $("#errorList").html(textStatus);
               $("#errorList").append("<br/>"+HttpRequest.status);
               $("#errorList").append("<br/>"+errorThrown);
               $("#errorList").append("<br/>");
               $("#errorList p").each(function(){
                   $(this).remove();
               });
               $("#errorList").append("<p>" + errorThrown.responseText + "</p>");
           },
           error: function(HttpRequest, textStatus, errorThrown){
               $("#errorList").html(textStatus);
               $("#errorList").append("<br/>"+HttpRequest.status);
               $("#errorList").append("<br/>"+HttpRequest.readyState);
               $("#errorList").append("<br/>"+HttpRequest.responseText);
           }
    });
    //$.post("http://localhost:8080"+$(formId+"action").val(),convertForm2Json(formId),function(){alert("1");},"json");
}
</script>
</body>
</html>